//
//  BHCircleSearchBarView.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/7/6.
//

import UIKit

class BHCircleSearchBarView: UIView {

    var begainAddMoreCircle:(() -> Void)?
    var goSearchBlock:((String) -> Void)?
    
    
    @IBOutlet weak var search_textFiled: UITextField!
    
    @IBOutlet weak var seachBackView: UIView!
    
    @IBOutlet weak var safeToTop: NSLayoutConstraint!
    static func loadFromXib() -> BHCircleSearchBarView {
        let viewArray = Bundle.main.loadNibNamed("BHCircleSearchBarView", owner: nil, options: nil)
        let view: BHCircleSearchBarView = viewArray![0] as! BHCircleSearchBarView
        return view
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.seachBackView.addLayerCorner(15, 0.5, .color_dadada)

        self.safeToTop.constant = UIScreen.stateBarHeight
        
        self.search_textFiled.delegate = self
    }
    
    static var height: CGFloat {
        get {
            return UIScreen.begainY
        }
    }
    
    @IBAction func addBtnAct(_ sender: UIButton) {
        self.begainAddMoreCircle?()
    }
    
}


extension BHCircleSearchBarView : UITextFieldDelegate {
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
    
    func textFieldDidEndEditing(_ textField: UITextField) {
        self.goSearchBlock?(textField.text ?? "")
    }
}
